<?php namespace Admin\Controller;
class BrandController extends CommonController{
	private $model;
	public function __auto(){
		$this->model=new \Common\Model\Brand;
	}
	//显示页面
	public function index(){
		$data=$this->model->orderBy('sort')->get();
		View::with('data',$data);
		View::make();
	}
	//添加页面
	public function add(){
		if(IS_POST){
			if($this->model->store()){
				View::success('添加成功',U('Brand/index'));
			}
			View::error($this->model->getError());
		}
		View::make();
	}
	public function del(){
		$bid=Q('get.bid',0,'intval');
		$this->model->where(array('bid'=>$bid))->delete();
		View::success('删除成功');
	}
	public function edit(){
		$bid=Q('get.bid',0,'intval');
		if(IS_POST){
			if($this->model->edit($bid)){
				View::success('修改成功',U('Brand/index'));
			}
			View::error($this->model->getError());
		}

		$oldData=$this->model->where(array('bid'=>$bid))->find();
		View::with('oldData',$oldData);
		View::make();
	}
	public function sort(){
		$bid=$_POST['bid'];
		$sort=$_POST['sort'];
		$this->model->where(array('bid'=>$bid))->save(array('sort'=>$sort));
	}
}


 ?>